﻿//
// Created by francklinson on 2021/3/25.
//

#ifndef CPPPRIMERPLUSREADINGCODES_QUEUE_H
#define CPPPRIMERPLUSREADINGCODES_QUEUE_H

// queue.h -- interface for a queue
// This queue will contain Customer items
class Customer
{
private:
    long arrive;     // arrival time for customer
    int processTime; // processing time for customer
public:
    Customer()
    { arrive = processTime = 0; }

    void set(long when);

    long when() const
    { return arrive; }

    int ptime() const
    { return processTime; }
};

typedef Customer Item;


class Queue
{
private:
// class scope definitions
    // Node is a nested structure definition local to this class
    struct Node
    {
        Item item;
        struct Node *next;
    };
    enum
    {
        Q_SIZE = 10
    };
// private class members
    Node *front;    // pointer to front of Queue
    Node *rear;     // pointer to rear of Queue
    int items;       // current number of items in Queue
    const int qsize; // maximum number of items in Queue
    // preemptive definitions to prevent public copying 伪私有方法
    Queue(const Queue &q) : qsize(0) // 复制
    {}

    Queue &operator=(const Queue &q)  // 赋值
    { return *this; }

public:
    Queue(int qs = Q_SIZE); // 构造函数  qs为长度限制
    ~Queue(); // 析构函数

    bool isEmpty() const; // 队列是否为空

    bool isFull() const; // 队列是否满

    int queueCount() const; // 返回队列长度

    bool enQueue(const Item &item); // 入队
    bool deQueue(Item &item); // 出队
};


#endif //CPPPRIMERPLUSREADINGCODES_QUEUE_H
